package main

import (
	"app/internal/store/conf"
	"app/internal/store/service"
	"app/util"
	"flag"
	"os"
	"runtime"
)

var (
	confpath string
)

func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	flag.StringVar(&confpath, "conf", "", "default config path")
	flag.Parse()
	cf := conf.LoadConfig(confpath)
	service.InitService(&cf)
	ms := util.NewMessageloop(2)
	go func() {
		defer ms.Signal()
		service.GetServiceInstance().WaitMsg()
	}()
	go func() {
		defer ms.Signal()
		handler := func(s os.Signal, arg interface{}) {
			arg.(*service.Service).Close()
			ms.Exit()
		}
		util.WaitSignal(handler, service.GetServiceInstance())
	}()
	go func() {
		defer ms.Signal()
		util.ProcessNotify(cf.Monitor.GetMonitorAddr())
	}()

	ms.Wait()
}
